/*
This software is copyright 2009 Matthew Wilson matthew@wilson.org
and available under the Artistic License 2 ("AL2") as documented at
http://jsmeta.googlecode.com
*/

function Print() {
  print(__slice.call(arguments || '', 0).join('\n'));
};

var JSMetaPadInputString;
var MGrammarInput = read(arguments[0]);
var InstanceInput = read(arguments[1]);

var startTime;

var r = Module.Parse(function(){
  JSMetaPadInputString = InstanceInput;
  
  Print('Compiling and importing MGrammar grammar/parser');
  
  Module(function Microsoft__M__Grammar(l) {
    l.__Language(MGrammar).Export();
  });
  return Module.Exec(function runit(l) {
    l.__Import('Microsoft.M.Grammar');
    l.__Init(MGrammarInput);
    Print('Parsing and compiling MGrammar input');
    startTime = new Date().getTime();
    return [l.Microsoft.M.Grammar.MGrammar.Main(), l];
  });
});

printingResult = true;
var duration = (new Date()).getTime() - startTime;

if (!r.outcome) {
  Print('Error: ' + typeof(r.errorMsg)=='undefined' ? 'Unknown' : r.errorMsg);
} else {
  Print(r.result, duration + ' ms', r.reTests, r.activations);
}
























